package com.pine.sunshineelder.waiter.web.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pine.sunshineelder.common.StringHelper;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.dto.QueryResult;
import com.pine.sunshineelder.waiter.ao.ElderAideAo;
import com.pine.sunshineelder.waiter.service.ElderAideService;
import com.pine.sunshineelder.waiter.vo.ElderAideVo;

@RestController
@RequestMapping("/api/elderaide")
public class ElderAideHandler implements StringHelper{
	@Autowired
	ElderAideService service;
	
	@PostMapping("/add")
	public JSONResponse registerElderBed(ElderAideAo ao) throws Exception {
		ElderAideVo elderAide = service.addElderAide(ao);

		return JSONResponse.ok(elderAide);
	}
	
	@GetMapping("/{id}")
	public JSONResponse selectByElderAideId(@PathVariable("id") String id) throws Exception {
		ElderAideVo elderAideId = service.selectById(id);
		return JSONResponse.ok(elderAideId);
	}
	
	@DeleteMapping("/del/{id}")
	public JSONResponse deleteElderAide(@PathVariable("id") String id) throws Exception{
		service.deleteElderAideById(id);
		return JSONResponse.ok();
	}
	
	@GetMapping("/list")
	public JSONResponse listElderAide(String key, String pageNo, String pageSize) throws Exception {
		System.out.println("--------->");
		Integer pageNoUse = parseInt(pageNo, null);
		Integer pageSizeUse = parseInt(pageSize, null);
		QueryResult result = service.queryByKey(key, pageNoUse, pageSizeUse);
		return JSONResponse.ok(result);
	}
	
	
	
}
